package com.springboot.jeesite.common.queue.activemq;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.activemq.artemis.jms.client.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Destination;
import java.util.ArrayList;
import java.util.List;

/**
 * MqProducerRestController
 *
 * @author xxx
 * @version xxx
 */
@RestController
@RequestMapping(value = "rest/mq/producer")
@Api(value = "ActiveMQ队列任务云接口", description = "ActiveMQ队列任务云接口")
public class MailProducerRestController {
    @Autowired
    private MailProducer mailProducer;

    @RequestMapping(value = {"sendMessage"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(value = "ActiveMQ队列云发送信息(Content-Type为text/html)", notes = "ActiveMQ队列云发送信息(Content-Type为text/html)")
    @ApiImplicitParam(name = "message", value = "信息", required = false, dataType = "String", paramType = "query")
    public void sendMessage(@RequestParam(required = false) String message) {
        Destination destination = new ActiveMQQueue(MailProducer.ActiveMQQueueKey);
        mailProducer.sendMessage(destination, message);
    }

    @RequestMapping(value = {"sendMail"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(value = "ActiveMQ队列云发送邮件(Content-Type为text/html)", notes = "ActiveMQ队列云发送邮件(Content-Type为text/html)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "toMailAddr", value = "接收邮件", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "subject", value = "邮件主题", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "message", value = "邮件内容", required = false, dataType = "String", paramType = "query")
    })
    public void sendMail(@RequestParam(required = false) String toMailAddr, @RequestParam(required = false) String subject, @RequestParam(required = false) String message) {
        List<String> list = new ArrayList();
        list.add(toMailAddr);
        list.add(subject);
        list.add(message);
        Destination destination = new ActiveMQQueue(MailProducer.ActiveMQQueueKeySendMailList);
        mailProducer.sendMessage(destination, list);
    }

    @RequestMapping(value = {"sendMailObject"}, method = {RequestMethod.POST, RequestMethod.GET})
    @ApiOperation(value = "ActiveMQ队列云发送邮件(Content-Type为text/html)", notes = "ActiveMQ队列云发送邮件(Content-Type为text/html)")
    @ApiImplicitParam(name = "email", value = "email信息{toMailAddr,subject,message}", required = false, dataType = "Email", paramType = "query")
    public void sendMailObject(Email email) {
        Destination destination = new ActiveMQQueue(MailProducer.ActiveMQQueueKeySendMailObject);
        mailProducer.sendMessage(destination, email);
    }
}
